﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using Microhard.Permission.Models;
using System.Web.Security;

namespace Microhard.Permission_MembershipImpl
{
    public class PermissionMapBuilder
    {
        public static void InitMap()
        {
            #region User
            Mapper.CreateMap<User, MembershipUser>()
                .ForMember(dst => dst.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dst => dst.UserName, opt => opt.MapFrom(src => src.UserName));
            Mapper.CreateMap<MembershipUser, User>()
                .ForMember(dst => dst.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dst => dst.UserName, opt => opt.MapFrom(src => src.UserName))
                .ForMember(dst => dst.password, opt => opt.Ignore());
            Mapper.CreateMap<User, aspnet_User>();
            Mapper.CreateMap<aspnet_User, User>()
                 .ForMember(dst => dst.Email, opt => opt.MapFrom(src => src.aspnet_Membership.Email))
                 .ForMember(dst => dst.ID, opt => opt.MapFrom(src => src.UserId))
                 .ForMember(dst => dst.UserName, opt => opt.MapFrom(src => src.UserName));
            #endregion

            #region Resouce
            Mapper.CreateMap<Resouce, MicroHard_Resource>();
            Mapper.CreateMap<MicroHard_Resource, Resouce>();
            #endregion

            #region ResouceType
            Mapper.CreateMap<ResouceType, MicroHard_ResourceType>();
            Mapper.CreateMap<MicroHard_ResourceType, ResouceType>();
            #endregion

            #region Role
            Mapper.CreateMap<Role, aspnet_Role>();
            Mapper.CreateMap<aspnet_Role, Role>();
            #endregion

            #region Permission
            Mapper.CreateMap<MicroHard_Permission, Microhard.Permission.Models.Permission>();
            Mapper.CreateMap<Microhard.Permission.Models.Permission, MicroHard_Permission>();
            #endregion

            #region Operation
            Mapper.CreateMap<Operation, MicroHard_Operation>();
            Mapper.CreateMap<MicroHard_Operation, Operation>();
            #endregion

            #region Group
            Mapper.CreateMap<Group, MicroHard_Group>()
                 .ForMember(dst => dst.OrgID, opt => opt.MapFrom(src => src.ID))
                 .ForMember(dst => dst.OrgName, opt => opt.MapFrom(src => src.Name));
            Mapper.CreateMap<MicroHard_Group, Group>()
                 .ForMember(dst => dst.ID, opt => opt.MapFrom(src => src.OrgID))
                 .ForMember(dst => dst.Name, opt => opt.MapFrom(src => src.OrgName));
            #endregion

            #region DataCollection
            Mapper.CreateMap<PermissionDataCollection, MicroHard_DataCollection>();
            Mapper.CreateMap<MicroHard_DataCollection, PermissionDataCollection>();
            #endregion

            #region DataPermission
            Mapper.CreateMap<DataPermission, MicroHard_DataPermission>();
            Mapper.CreateMap<MicroHard_DataPermission, DataPermission>();
            #endregion

            #region Dictionary
            Mapper.CreateMap<DictionaryModel, MicroHard_Dictionary>();
            Mapper.CreateMap<MicroHard_Dictionary, DictionaryModel>();
            #endregion

            #region UserOperationLog
            Mapper.CreateMap<UserOperationLogModel, Microhard_UserOperationLog>();
            Mapper.CreateMap<Microhard_UserOperationLog, UserOperationLogModel>();
            #endregion
        }
    }
}
